//
// Created by 11401 on 25-7-7.
//

#include "openmv.h"
#include "usart.h"
#include "Task_received.h"
#include "bsp_ats.h"
openmv_t  _openmv;
uint8_t   openmv_rx[128];
uint8_t   openmv_tx[128];

void bsp_openmv_init(UART_HandleTypeDef *huart)
{

    openmv_t  *openmv;
    openmv=&_openmv;
    memset(openmv, 0, sizeof(openmv_t));
    openmv->huart = huart;

    HAL_UARTEx_ReceiveToIdle_IT(openmv->huart,
                                openmv->rx_buffer,
                                sizeof(openmv->rx_buffer));
    __HAL_UART_ENABLE_IT(openmv->huart,UART_IT_IDLE);
    __HAL_DMA_DISABLE_IT(&hdma_usart3_rx,DMA_IT_HT);
}

void bsp_openmv_tx(uint8_t action_command)
{
HAL_UART_Transmit_DMA(_openmv.huart, &action_command, 1);
}

void HAL_UARTEx_RxEventCallback(UART_HandleTypeDef* huart, uint16_t Size)
{
    HAL_UART_DMAStop(huart);
    //openmv信息
    if (huart->Instance == USART3)
    {
        //队列通知

        HAL_UARTEx_ReceiveToIdle_IT(_openmv.huart,
                                    _openmv.rx_buffer,
                                    sizeof(_openmv.rx_buffer));
        __HAL_UART_ENABLE_IT(_openmv.huart, UART_IT_IDLE);
        __HAL_DMA_DISABLE_IT(&hdma_usart3_rx, DMA_IT_HT);
    }
    //ATS522信息读取
    if (huart->Instance == UART4)
    {
        bsp_ats522_callback(huart);
    }
    //任务发布
    if (huart->Instance == USART1)
    {
        bsp_task_notifications_callback(task_rx_tx.huart, Size);
    }
}


